<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/tagDeclare.jsp"%>
<%@include file="/headDeclare.jsp"%>
<html>
 <head>
<style type="text/css"> 
	fieldset,table,tr,td {margin:0; padding:0;}
	td {padding:0 5px 0 10px;border:1px;}
	form label {font-weight:bold;}
	table{border-collapse: collapse;}
  </style>

  <script type="text/javascript">
	$(document).ready(function() {
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            $("#searchForm").submit();
        });
        //批量删除
        $("#btn_batch_del").click(function(){
        	var roleId = $("#roleId").val();
        	var queryString = $("#searchForm").formSerialize();
            queryString = encodeURIComponent(queryString);
        	var ids = null;
        	$("input[name='checkName']:checkbox:checked").each(function(){ 
        		if(ids == null)
        			ids = $(this).val();
        		else
        		    ids +=","+$(this).val() ;
        	}) ;
        	if(ids ==null)return;
        	if(ids == "")
        		{
        			$.ligerDialog.alert("请选择");
        			return;
        		}
        	location.href = "<%=basePath%>roleuser/batchDelete.do?ids=" + ids +"&roleId="+roleId+"&qs=" + queryString;
        });
  
      
	}); 
	
	function insert(roleId){
        $.ligerDialog.open({ url: 'roleuser/choose.do?roleId='+roleId, height: 400, width: 600, buttons: [
            { text: '取消', onclick: function (item, dialog) { dialog.close(); } }
         ], isResize: true,title:'新增'
        });
    }

	
	function deleteItem(roleId,userId){
		var url = "<%=basePath%>roleuser/delete.do";
		$.post(url,{roleId:roleId,userId:userId},function(data){
			var responseJson = eval('(' + data + ')');
			   if(responseJson.code==0)
			   {
				   $.ligerDialog.error("删除出错");
	         		return;
			   }else{
		    		window.searchForm.submit();
			   }
		});
    	
	}
	
  </script>
 </head>

 <body>
 
 <div style="width: 100%;">
  <div style="margin: auto;margin-top: 10px;" >
      <form id="searchForm"  method="post" action="roleuser/list.do">
      <input type="hidden" name="id" id="roleId" value="${role.id }" />
        <table>
          <tr>
            <td><label for="name">用户名:</label></td>
            <td><input type="text" class="ldText" name="userName" id="userName" value="${userName }"/></td>
            <td><input type="submit" id="btn_search" class="ldBtnBlue" value="查询"  /></td>
          </tr>
        </table>
      </form>
  </div>
  <hr />
  <div>
  	<table border="0" cellspacing="0" cellpadding="0" width="100%" class="ld-datagrid">
	    <tr>
	      <th align="center" >
               <span style="cursor: pointer" onclick="changeStatus('all')">全</span>/<span style="cursor: pointer" onclick="changeStatus('invert')">反</span>
		  </th>
          <th >用户名</th>
          <th >姓名</th>
          <th >身份</th>
          <th >操作</th>
 	    </tr> 
	  	<c:forEach items="${list}" var="user" varStatus="status">
	  	<tr>
	  	  <td><input name="checkName" type="checkbox" value="${user.id }" /></td>
	  	  <td >${user.userName }</td>
	  	  <td >${user.showName }</td>
	  	  <td >${role.roleName}
		  </td>
	  	  <td >
	  	  		<input type="button" value="删除" class="ldBtnLink" onclick="deleteItem('${role.id }','${user.id }')" />
	  	  </td>
	  	</tr>
	  	</c:forEach>
  	</table>
  </div>
	<hr />
  <div>
  <div style="float: left;">
  	 <input type="button" id="btn_batch_del" class="ldBtnGray" value="批量删除" />
  	 <input type="button" id="btn_insert" onclick="insert('${role.id}')" value="新增" class="ldBtnGray" />
 </div>
 </body>
</html>

